package um.android;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class OptionsActivity extends Activity {
	Button libreta,inscrip,desinscrip;
	BroadcastReceiver SServiceLibreta, SServiceDesinsc;
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        IntentFilter filter = new IntentFilter();
        filter.addAction("um.android.libreta");
        IntentFilter filterdesinsc = new IntentFilter();
        filterdesinsc.addAction("um.android.desinsc");
 
        setContentView(R.layout.options);
        
        libreta = (Button) findViewById(R.id.libreta);
        inscrip = (Button) findViewById(R.id.inscrip);
        desinscrip = (Button) findViewById(R.id.desinscrip);
        
        libreta.setOnClickListener(new Button.OnClickListener()
        {
            public void onClick(View v)
            {
            	 Intent i = new Intent();
                 i.setAction("um.android.requestlib");
                 i.putExtra("getlibreta","1");
                 sendBroadcast(i);
            }
        });
        
        SServiceLibreta = new BroadcastReceiver() {

    	    @Override
    	    public void onReceive(Context context, Intent intent) {
        	  // TODO Auto-generated method stub
    	    	Log.d("OPTIONDESNSC", "broadcast recived");
        	  String SSdata = intent.getStringExtra("libreta");	  
        	  
        	  Intent libAct = new Intent(OptionsActivity.this, LibretaActivity.class);
        	  libAct.putExtra("libreta", SSdata);
              startActivityForResult(libAct, 0);
    	    
    	    
    	    }
        	 
        	};
        	
        	registerReceiver(SServiceLibreta, filter);
        
        
        
        
        inscrip.setOnClickListener(new Button.OnClickListener()
        {
            public void onClick(View v)
            {
            	Intent i = new Intent();
                i.setAction("um.android.requestinsc");
                i.putExtra("getinsc","0");
                sendBroadcast(i);
            
            }
        });
        
        desinscrip.setOnClickListener(new Button.OnClickListener()
        {
            public void onClick(View v)
            {
            	
            	Intent i = new Intent();
                i.setAction("um.android.requestinsc");
                i.putExtra("getinsc","1");
                sendBroadcast(i);
            }
        }); 
        
        SServiceDesinsc = new BroadcastReceiver() {

    	    @Override
    	    public void onReceive(Context context, Intent intent) {
        	  // TODO Auto-generated method stub
        	  
        	  String SSdata = intent.getStringExtra("data");	  
        	  
        	  Intent libAct = new Intent(OptionsActivity.this, DesinscActivity.class);
        	  libAct.putExtra("data", SSdata);
              startActivityForResult(libAct, 0);
    	    
    	    
    	    }
        	 
        	};
        	
        	registerReceiver(SServiceDesinsc, filterdesinsc);
	}

	
	
	
	
	
	
	
	
	
	
	
	
	

	@Override
	public void onDestroy() {
		super.onDestroy();
		unregisterReceiver(SServiceLibreta);
		unregisterReceiver(SServiceDesinsc);
		
	}
}